% Autor:
% Data: 09-12-2011


printBoard(Vars, X, Y) :-
	nl,
	(X @>= 5, Y @>= 6 -> printBoard_(Vars, X, Y, 1) ;
					   printAsciiBoard(Vars, X, Y)).

printBoard_([], X, Y, Idx) :- Idx #= X * Y +1, !.
printBoard_([P|T], X, Y, Idx) :-
        piece(P, _P),
        write(' '), write(_P),
        (Idx mod X #= 0 -> nl ; write(' ')),
        Idx2 is Idx + 1,
        printBoard_(T, X, Y, Idx2).

piece(0, '-').
piece(1, 'A').
piece(2, 'B').
piece(3, 'C').
piece(4, 'D').
piece(5, 'E').
piece(6, 'F').
piece(7, 'G').
piece(8, 'H').
piece(9, 'I').
piece(10, 'J').
piece(11, 'K').
piece(12, 'L').

printAsciiBoard(Board, X, Y) :-
        nl, printAsciiBoard_(Board, X, Y, 1, []), nl.

printAsciiBoard_([], _, _, _, _).
printAsciiBoard_([P|T], X, Y, Idx, Ps) :-
        append(Ps, [P], Ps_),
        Idx2 is Idx + 1,
        (Idx mod X #= 0 ->
                printLinePieces(Ps_, X), printAsciiBoard_(T, X, Y, Idx2, []) ;
                printAsciiBoard_(T, X, Y, Idx2, Ps_)).

printLinePieces(Pieces, X) :-
        printLinePieces_(Pieces, 1, X).

printLinePieces_(_, 7, _).
printLinePieces_(Pieces, N, X) :-
        printPiecesParts(Pieces, N, X, X),
        nl,
        N2 is N + 1,
        printLinePieces_(Pieces, N2, X).

printPiecesParts([], _, 0, _).
printPiecesParts([P|T], N, X, Xmax) :-
        getAsciiPiece(P, N, PAscii),
        %write(' '),
        write(PAscii),
        X2 is X - 1,
        printPiecesParts(T, N, X2, Xmax).

printPiece_([]).
printPiece_([H|T]) :-
        write(H), nl,
        printPiece_(T).
printPiece(PieceNumber) :-
        getAsciiPiece(PieceNumber, Piece),
        printPiece_(Piece).

getAsciiPiece(0, 1, '           ').
getAsciiPiece(0, 2, '           ').
getAsciiPiece(0, 3, '           ').
getAsciiPiece(0, 4, '           ').
getAsciiPiece(0, 5, '           ').
getAsciiPiece(0, 6, '           ').

getAsciiPiece(1, 1, ' _/\\__  _  ').
getAsciiPiece(1, 2, '|     \\/ | ').
getAsciiPiece(1, 3, ' \\   A    \\').
getAsciiPiece(1, 4, ' /        /').
getAsciiPiece(1, 5, '|_/\\__  _| ').
getAsciiPiece(1, 6, '      \\/   ').

getAsciiPiece(2, 1, ' _  __/\\_  ').
getAsciiPiece(2, 2, '| \\/     | ').
getAsciiPiece(2, 3, ' \\   B    \\').
getAsciiPiece(2, 4, ' /        /').
getAsciiPiece(2, 5, '|_  __/\\_| ').
getAsciiPiece(2, 6, '  \\/       ').

getAsciiPiece(3, 1, '  _  __/\\_ ').
getAsciiPiece(3, 2, ' | \\/     |').
getAsciiPiece(3, 3, '/    C   / ').
getAsciiPiece(3, 4, '\\        \\ ').
getAsciiPiece(3, 5, ' |_  __/\\_|').
getAsciiPiece(3, 6, '   \\/      ').

getAsciiPiece(4, 1, ' _/\\__  _ ').
getAsciiPiece(4, 2, '|     \\/ |').
getAsciiPiece(4, 3, ' \\   D  / ').
getAsciiPiece(4, 4, ' /      \\ ').
getAsciiPiece(4, 5, '|_/\\__  _|').
getAsciiPiece(4, 6, '      \\/  ').

getAsciiPiece(5, 1, '  _/\\__  _  ').
getAsciiPiece(5, 2, ' |     \\/ | ').
getAsciiPiece(5, 3, '/     E    \\').
getAsciiPiece(5, 4, '\\          /').
getAsciiPiece(5, 5, ' |_/\\__  _| ').
getAsciiPiece(5, 6, '       \\/   ').

getAsciiPiece(6, 1, ' _  __/\\_ ').
getAsciiPiece(6, 2, '| \\/     |').
getAsciiPiece(6, 3, ' \\   F  / ').
getAsciiPiece(6, 4, ' /      \\ ').
getAsciiPiece(6, 5, '|_/\\__  _|').
getAsciiPiece(6, 6, '      \\/  ').

getAsciiPiece(7, 1, '  _/\\__  _ ').
getAsciiPiece(7, 2, ' |     \\/ |').
getAsciiPiece(7, 3, '/    G   / ').
getAsciiPiece(7, 4, '\\        \\ ').
getAsciiPiece(7, 5, ' |_/\\__  _|').
getAsciiPiece(7, 6, '       \\/  ').

getAsciiPiece(8, 1, ' _  __/\\_  ').
getAsciiPiece(8, 2, '| \\/     | ').
getAsciiPiece(8, 3, ' \\   H    \\').
getAsciiPiece(8, 4, ' /        /').
getAsciiPiece(8, 5, '|_/\\__  _| ').
getAsciiPiece(8, 6, '      \\/   ').

getAsciiPiece(9, 1, '  _/\\__  _  ').
getAsciiPiece(9, 2, ' |     \\/ | ').
getAsciiPiece(9, 3, '/     I    \\').
getAsciiPiece(9, 4, '\\          /').
getAsciiPiece(9, 5, ' |_  __/\\_| ').
getAsciiPiece(9, 6, '   \\/       ').

getAsciiPiece(10, 1, '  _  __/\\_  ').
getAsciiPiece(10, 2, ' | \\/     | ').
getAsciiPiece(10, 3, '/     J    \\').
getAsciiPiece(10, 4, '\\          /').
getAsciiPiece(10, 5, ' |_/\\__  _| ').
getAsciiPiece(10, 6, '       \\/   ').

getAsciiPiece(11, 1, '  _/\\__  _ ').
getAsciiPiece(11, 2, ' |     \\/ |').
getAsciiPiece(11, 3, '/    K   / ').
getAsciiPiece(11, 4, '\\        \\ ').
getAsciiPiece(11, 5, ' |_  __/\\_|').
getAsciiPiece(11, 6, '   \\/      ').

getAsciiPiece(12, 1, ' _/\\__  _ ').
getAsciiPiece(12, 2, '|     \\/ |').
getAsciiPiece(12, 3, ' \\   L  / ').
getAsciiPiece(12, 4, ' /      \\ ').
getAsciiPiece(12, 5, '|_  __/\\_|').
getAsciiPiece(12, 6, '  \\/      ').